const http = require('http');
const fs = require('fs');
http.createServer(function (request, response){
    fs.readFile('./example.txt','utf8',function (err, data) {  
        if (err) {  
        response.writeHead(500, {'Content-Type': 'text/plain'});  
        response.write('Error reading file: ' + err);  
        response.end(); 
        return;  
        }  

        response.writeHead(200, {'Content-Type': 'text/plain'});  
        response.write(data); // 返回文件内容 
        response.end(); //结束响应 
        });  
       }).listen(8000, '127.0.0.1');  
       
       console.log('Server running on port8000.');